package com.tkc.common.util;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.stereotype.Component;

import com.tkc.common.constant.TimeConstants;

/**
 * 
 * @Function:时间处理工具类
 * 
 * @Project :assessmenttask 
 * @Package :com.tkc.controller.util 
 * @File :TimeHelper.java 
 * @ClassName: TimeHelper  
 * 
 * @author tankaichao 
 * @email cgztkc@126.com 
 * @Date 2016年8月9日下午5:58:53
 * @since JDK 1.8 
 *
 */
@Component("timeHelper")
public class TimeHelperUtil {
	
	/**
	 * 获取当前系统时间戳
	 * @return
	 */
	public static int transformpresenttime() {
		long time = System.currentTimeMillis() / 1000;
		return (int) time;
	}
	
	/**
	 * 时间戳的转换
	 * @param TimeParam
	 * @return
	 */
	public static Integer transformtimetamp(String TimeParam) {
		if(TimeParam==null||TimeParam.equals("")){
			return null;
		}
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date;
		long time = 0000000000;
		try {
			date = dateFormat.parse(TimeParam);
			time = date.getTime() / 1000;
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return (int)time;
	}
	
	/**
	 * 获取当前系统时间
	 * @param TimeParam
	 * @return
	 */
	public static String getSystemTime() {
		Date now = new Date(); 
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String strTime = dateFormat.format(now);
		return strTime;
	}
	
	
	/**
     * 根据自定义格式和字符串获取对应系统时间
     * @param format
     * @param str
     * @return
     */
    public static Date getDateFormatter(String format, String str) {
    	
    	SimpleDateFormat df = new SimpleDateFormat(format);
    	
    	Date date = null;
    	
    	try {
			date = df.parse(str);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
    	return date;
	}
    
    /**
     * timestamp类型转换成string型
     * @param timestamp
     * @return
     */
    public static String gettimestampToString(Timestamp timestamp){
    	SimpleDateFormat df = new SimpleDateFormat(TimeConstants.Time_Formats.get(3));
    	String timestampStr =df.format(timestamp);
    	return timestampStr;
    }
    
    public static String transformExecutiveTime(long executiveTime){
    	 String result = "";
    	 if (executiveTime >=3600000) {
    		long hour = executiveTime/3600000;
			result += hour + " 小时 ";
			executiveTime -= hour*3600000;
		}
    	 if (executiveTime >=60000) {
			long minute = executiveTime/60000;
			result += minute + " 分钟 ";
			executiveTime -= minute*60000;
		}
    	 if (executiveTime >=1000) {
			long second = executiveTime/1000;
			result += second + " 秒 ";
			executiveTime -= second*1000;
		}
    	 result += executiveTime + " 毫秒";
    	 return result;
    }
    
    
}
